package com.websocket.service;

import org.java_websocket.WebSocket;

import java.security.Principal;

public class WebSocketConnection {
    private final WebSocket connection;

    public WebSocketConnection(WebSocket connection) {
        this.connection = connection;
    }

    public void close() {
        connection.close();
    }

    /**
     * @param code {@link org.java_websocket.framing.CloseFrame}
     */
    public void close(int code) {
        connection.close(code);
    }

    /**
     * @param code {@link org.java_websocket.framing.CloseFrame}
     */
    public void close(int code, String message) {
        connection.close(code, message);
    }

    public Principal getPrincipal() {
        Attachment attachment = connection.getAttachment();
        return attachment.getPrincipal();
    }

    public Object getAttribute(String key) {
        Attachment attachment = connection.getAttachment();
        return attachment.getAttribute(key);
    }

    public void putAttribute(String key, Object value) {
        Attachment attachment = connection.getAttachment();
        attachment.putAttribute(key, value);
    }


}
